from openai import OpenAI
import base64
import requests

client = OpenAI(
	base_url="https://ai.gitee.com/v1",
	api_key="GL12Q58RIGC2T65JXAWRP3XSX9GEC44YRGTGQ216",
)

response = client.images.generate(
	prompt="她倚在雕花栏杆旁，夕阳的金辉漫过肩头，给乌黑的卷发镀上一层朦胧的光晕。几缕碎发垂在光洁的额前，被风轻轻掀起时，露出眉骨处细腻的绒毛。那双眼睛像浸在清泉里的黑曜石，眼尾微微上挑，笑起来便漾开两汪月牙，眼睫忽闪间，仿佛有蝶翼在颤动。鼻梁挺翘得恰到好处，鼻尖带着点自然的粉，与下颌线的利落弧度形成柔中带刚的美感。嘴唇是新鲜樱桃的色泽，说话时会先抿起一个浅浅的梨涡，声音像山涧溪流撞在鹅卵石上，清润又带点甜。​她抬手拢头发的瞬间，皓腕翻转如白瓷，指尖涂着半透明的裸色指甲油，与米白色连衣裙的蕾丝花边相映成趣。裙摆随着晚风轻轻摆动，露出脚踝处纤细的银链，走动时叮当作响，像把月光敲成了碎玉。",
	model="FLUX.1-dev",
	size="1024x1024",
	extra_body={
		"num_inference_steps": 20,
		"guidance_scale": 7.5,
		"seed": 42,
	},
)

for i, image_data in enumerate(response.data):
	if image_data.url:
		# Download from URL
		ext = image_data.url.split('.')[-1].split('?')[0] or "jpg"
		filename = f"FLUX.1-dev-output-{i}.{ext}"
		response = requests.get(image_data.url, timeout=30)
		response.raise_for_status()
		with open(filename, "wb") as f:
			f.write(response.content)
		print(f"Downloaded image to {filename}")
	elif image_data.b64_json:
		# Decode base64
		image_bytes = base64.b64decode(image_data.b64_json)
		filename = f"FLUX.1-dev-output-{i}.jpg"
		with open(filename, "wb") as f:
			f.write(image_bytes)
		print(f"Saved image to {filename}")